package com.zjbti.commonview;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class RadioButtonActivity extends AppCompatActivity  implements CompoundButton.OnCheckedChangeListener{
    TextView textView2;
    TextView textView4;
    RadioGroup radioGroup;
    CheckBox checkBox1;
    CheckBox checkBox2;
    CheckBox checkBox3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_radio_button);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        textView2= findViewById(R.id.textView2);
        textView4= findViewById(R.id.textView4);
        radioGroup= findViewById(R.id.radioGroup);
        checkBox1= findViewById(R.id.checkBox1);
        checkBox2= findViewById(R.id.checkBox2);
        checkBox3= findViewById(R.id.checkBox3);
        checkBox1.setOnCheckedChangeListener(this);
        checkBox2.setOnCheckedChangeListener(this);
        checkBox3.setOnCheckedChangeListener(this);
        radioGroup.setOnCheckedChangeListener((radioGroup, i)->{
            if(i == R.id.radioButton1){
                textView2.setText("你是男的");
            }else{
                textView2.setText("你是女的");
            }
        });

    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        String text = compoundButton.getText().toString();
        if(b){
            textView4.setText("你的喜好是"+text);
            Toast.makeText(getApplicationContext(),"你的喜好是"+text,Toast.LENGTH_SHORT).show();
        }else {
            textView4.setText("你取消了"+text);
            Toast.makeText(getApplicationContext(),"你取消了"+text,Toast.LENGTH_SHORT).show();

        }

    }
}